<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('app列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>所属用户：</label>
                            <input type="text" name="userName" autocomplete="off"/>
                        </li>
                        <li>
                            <label>文件名称：</label>
                            <input type="text" name="name" autocomplete="off"/>
                        </li>
                        <li>
                            <label>app名称：</label>
                            <input type="text" name="appName" autocomplete="off"/>
                        </li>
                        <li>
                            <label>app名称：</label>
                            <input type="text" name="appName" autocomplete="off"/>
                        </li>
                        <li class="select-time">
                            <label>上传时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-success " onclick="refreshAll()" data-toggle="tooltip" data-placement="bottom" data-trigger="hover" title="刷新未成功的数据">
                <i class="fa fa-refresh"></i> 刷新数据
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "cms/app";

    const statusMap = {
        0: '初始',
        1: '开始',
        2: '成功',
        3: '失败'
    }

    $(function () {
        $("[data-toggle='tooltip']").tooltip();
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "app",
            sortName: 'create_time',
            sortOrder: 'desc',
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'userName',
                    title: '所属用户'
                },
                {
                    field: 'name',
                    title: '文件名称'
                },
                {
                    field: 'appName',
                    title: 'app名称'
                },
                {
                    field: 'packName',
                    title: '包名'
                },
                {
                    field: 'size',
                    title: '大小'
                },
                {
                    field: 'version',
                    title: 'app版本号'
                },

                {
                    field: 'status',
                    title: 'app状态',
                    formatter: function (val) {
                        return statusMap[val]
                    }
                },
                {
                    field: 'relativeId',
                    title: '检测id'
                },
                {
                    field: 'batchId',
                    title: 'app批次号'
                },
                {
                    field: 'md5',
                    title: '文件md5'
                },
                {
                    field: 'ext1',
                    title: '上传类型'
                },
                {
                    field: 'createTime',
                    title: '提交时间'
                },
                {
                    field: 'updateTime',
                    title: '更新时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    width: 300,
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" onclick="onDownload(\''+row.attachPath+'\')"><i class="fa fa-download"></i>下载附件</a> ');
                        actions.push('<a class="btn btn-success btn-xs" onclick="onRefresh(\''+row.id+'\')"><i class="fa fa-refresh"></i>刷新数据</a> ');
                        actions.push('<a class="btn btn-danger btn-xs  " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-success btn-xs" onclick="downPdf(\''+row.id+'\')"><i class="fa fa-file-pdf-o"></i>PDF</a> ')
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function onDownload(url) {
        window.open(base + url)
    }

    function onRefresh(id) {
        $.modal.msg('已发送请求')
        $.get(prefix + '/refresh/' + id, function(res) {
            console.info('res:', res)
            $.modal.alert(res.msg)
            if(res.code == 0) {
                $.table.search()
            }
        })
    }
    function refreshAll() {
        $.modal.msg('已发送请求...')
        $.post(prefix + '/refreshAll', function(res) {
            $.modal.alert(res.msg)
            if(res.code == 0) {
                $.table.search()
            }
        })
    }

    function downPdf(id) {
        window.open(prefix + '/pdf?id='+id, '_blank')
    }
</script>
</body>
</html>